package com.gidgabs.modules.api.controller.discovery;

import com.gidgabs.common.annotation.LoginUserApi;
import com.gidgabs.common.utils.ReturnJson;
import com.gidgabs.common.utils.UploadVideoUtils;
import com.gidgabs.common.validator.Assert;
import com.gidgabs.dto.TbUserDto;
import com.gidgabs.dto.VideoDto;
import com.gidgabs.modules.api.service.discovery.DiscoveryUserService;
import com.gidgabs.modules.dao.TbUserDao;
import com.gidgabs.modules.entity.TbUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by tby on 2018/6/29.
 */
@Api("发现功能相关")
@RestController
@RequestMapping("api/discovery")
public class ApiDiscoveryController {

    @Autowired private DiscoveryUserService discoveryUserService;

    @ApiOperation(value = "获取用户/商户列表(按照粉丝数量排序)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize",value = "页面大小",dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "pageNo",value = "页码",dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "chooseType",value = "1商户,2普通用户",dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "token",value = "token",dataType = "string",paramType = "header")
    })
    @RequestMapping(value = "user/list", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    public ReturnJson<TbUserDto> queryList(Integer pageSize,Integer pageNo,Integer chooseType) {
        if (pageNo==null){
            pageNo=1;
        }if (pageSize==null){
            pageSize=10;
        }if (chooseType==null){
            chooseType=2;
        }
        return discoveryUserService.queryList(pageSize,pageNo,chooseType);
    }

    @ApiOperation(value = "关注或者取消关注某个用户/商户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId",value = "被关注/被取消关注的 用户id",dataType = "int",paramType = "form"),
            @ApiImplicitParam(name = "token",value = "token",dataType = "string",paramType = "header")
    })
    @RequestMapping(value = "follow", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public ReturnJson follow( Integer userId, @LoginUserApi TbUser tbUser) {
        Assert.isNull(userId,"userId不能为空");

        return discoveryUserService.follow(userId,tbUser);

    }
    @ApiOperation(value = "按名称或者编号来搜索用户/商户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "like",value = "名称或者编号",dataType = "string",paramType = "query"),
            @ApiImplicitParam(name = "chooseType",value = "1商户,2普通用户,不传或者0时查询所有",dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "token",value = "token",dataType = "string",paramType = "header")
    })
    @RequestMapping(value = "user/search", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    public ReturnJson<TbUserDto> userSearch(String like,Integer chooseType) {
        Assert.isBlank(like,"参数不能为空");
       return discoveryUserService.userSearch(like,chooseType);
    }


}
